﻿using UnityEngine;
using XLua;
using Yoozoo.UI.YGUI;

public class ListViewSizeTraslator : MonoBehaviour
{
    private LuaFunction sizeCalc;
    private ListView m_bindListViewObj;

    public void Awake()
    {
        var listViewObj = GetComponent<ListView>();
        if (listViewObj)
        {
            m_bindListViewObj = listViewObj;
            listViewObj.luaSizeGetter += myFunc;
        }
    }

    public void OnDestroy()
    {
        if (m_bindListViewObj)
        {
            m_bindListViewObj.luaSizeGetter -= myFunc;
        }
    }

    private Vector2 myFunc(int index)
    {
        if (sizeCalc != null)
            return sizeCalc.Func<int, Vector2>(index);

        return Vector2.zero;
    }

    public void SetSizeCalc(LuaFunction func)
    {
        this.sizeCalc = func;
    }
}
